<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WISSC轮滑教培服务网-查询系统</title>
    <#assign base=request.contextPath  />
    <link rel="icon" href="${base}/favicon.ico">
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>
    <script type="text/javascript" src="${base}/js/feng.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/css/hzw-city-picker.css">
    <script type="text/javascript" src="${base}/js/city-data.js"></script>
    <script type="text/javascript" src="${base}/js/hzw-city-picker.min.js"></script>
    <script type="text/javascript" src="${base}/js/city-zk.js"></script>
    <script type="text/javascript" src="${base}/js/province.js"></script>
</head>
<script>
    var defaults = {
        s1: 'provid',
        s2: 'cityid',
        s3: 'areaid',
        v1: null,
        v2: null,
        v3: null
    };
</script>
<body>
<form class="layui-form" action="" style="margin: 10px">
    <input type="hidden" id="id" value="${id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;单位名称</label>
        <div class="layui-input-inline">
            <input name="unitName" id="unitName" lay-verify="required" autocomplete="off" class="layui-input isNull"
                   type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">

            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;开始时间</label>
            <div class="layui-input-inline">
                <input name="startTime" id="startTime" lay-verify="required" autocomplete="off"
                       class="layui-input isNull" type="text">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;结束时间</label>
            <div class="layui-input-inline">
                <input name="endTime" id="endTime" lay-verify="required" autocomplete="off" class="layui-input isNull"
                       type="text">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;选择地区</label>
            <div class="layui-input-inline">
                <select name="provid" id="provid" lay-filter="provid" lay-verify="required" class="isNull">
                    <option value="">请选择国家</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="cityid" id="cityid" lay-filter="cityid" lay-verify="required">
                    <option value="">请选择省</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="areaid" id="areaid" lay-filter="areaid" lay-verify="required">
                    <option value="">请选择市</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;授权类型</label>
        <div class="layui-input-inline">
            <select name="grantType" lay-verify="required" id="grantType" class=" isNull">
                <option value="">请选择授权类型</option>
                <option value="1">授权实施会员单位</option>
                <option value="2">授权考核基地</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;授权等级</label>
        <div class="layui-input-inline">
            <select name="grantLevel" lay-verify="required" id="grantLevel" class=" isNull">
                <option value="">请选资质等级</option>
                <option value="1">1-10级实施单位</option>
                <option value="2">1-7级实施单位</option>
                <option value="3">1-4级实施单位</option>
                <option value="4">A场地</option>
                <option value="5">B场地</option>
                <option value="6">C场地</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;机构简介</label>
        <div class="layui-input-block">
            <textarea name="brief" id="brief" placeholder="请输入内容" class="layui-textarea isNull"></textarea>
            <span><span id="textNum">0</span>/200</span>
        </div>
    </div>
    <div class="layui-upload" id="img">
        <button type="button" class="layui-btn" id="test2" onclick="d()" style="background-color: #0092EF;">
            证书(最多五张图片)
        </button>
        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            预览图：
            <div class="layui-upload-list " id="demo2"></div>
        </blockquote>
    </div>
    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test1" style="background-color: #0092EF;">标志图片(要求单图片)</button>
        <div class="layui-upload-list" id="teamLogo" style="border: 1px solid #e6e6e6;height: 100px;width: 180px">
            <img src="${base}/team/getPhoto?path=${url}" id="demo1"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formDemo" type="button" onclick="onSubmit()"
                    id="aa" style="background-color: #0092EF;">立即提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '${base}/file/uploadFile'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //上传成功
                a = res.data;
                return res.data;
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })


</script>
<script>
    $('#brief').on("keyup", function () {
        $('#textNum').text($('#brief').val().length);//这句是在键盘按下时，实时的显示字数
        if ($('#brief').val().length > 200) {
            $('#textNum').text(200);//长度大于100时0处显示的也只是100
            $('#brief').val($('#brief').val().substring(0, 200));//长度大于100时截取钱100个字符
        }
    })
    var ids = $("#id").val();
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        $(function () {

            $.ajax({
                type: "POST",
                traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
                url: "${base}/authorization/getTeamCity",
                data: {id: $("#id").val()},
                success: function (req) {
                    var arr = req.split("/");
                    if (arr != null && arr != "") {
                        for (var i = 0; i < arr.length; i++) {

                            if (i == 0) {
                                $("#provid").find("option:contains('" + arr[i] + "')").attr("selected", true);
                            }
                            if (i == 1) {
                                $("#cityid").append("<option selected='selected' value='" + arr[i] + "' >" + arr[i] + "</option>");
                            }
                            if (i == 2) {
                                $("#areaid").append("<option selected='selected' value='" + arr[i] + "' >" + arr[i] + "</option>");
                            }
                        }
                    }
                    form.render('select');
                }
            });

        })
    })
</script>
<script>
    var fileIds = [];
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //多图片上传
        upload.render({
            elem: '#test2'
            , url: '/authorization/upload'
            , multiple: true
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" style="width:100px;height:100px">')
                });
            }
            , done: function (res) {
                layer.msg(res.msg)
                fileIds.push(res.data.fileId)
            }
        });
    })
</script>
<script type="text/javascript">

    var cityPicker = new HzwCityPicker({
        data: data,
        target: 'cityChoice',
        valType: 'k',
        hideCityInput: {
            name: 'city',
            id: 'city'
        },
        hideProvinceInput: {
            name: 'areaId',
            id: 'areaId',
            val: 'q'
        },
        callback: function () {
        }
    });

    cityPicker.init();

    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        laydate.render({
            elem: '#startTime' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#startTime' //指定元素
        });
        laydate.render({
            elem: '#endTime' //指定元素
        });

    });
    var a;

    //编辑
    function onSubmit() {
        if (!isNull()) {
            return;
        }
        if (fileIds == "") {
            fileIds = "kk";
        }
        var provid = $("#provid").val()
        var cityid = $("#cityid").val();
        var areaid = $("#areaid").val();
        var str = areaid.replace(/^\"|\"$/g, '');
        var sum = provid + "/" + cityid + "/" + str + "/";
        var jsonData = {};
        jsonData.unitName = $("#unitName").val();
        jsonData.startTime = new Date($("#startTime").val()).getTime()
        jsonData.endTime = new Date($("#endTime").val()).getTime()
        jsonData.city = sum;
        jsonData.grantType = $("#grantType").val();
        jsonData.grantLevel = $("#grantLevel").val();
        jsonData.brief = $("#brief").val();
        if (a == undefined) {
            jsonData.logoUrl = "${url}";
        } else {
            jsonData.logoUrl = a;
        }
        //id
        jsonData.id = $("#id").val();
        $.ajax({
            type: "POST", //提交方式
            traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
            url: "${base}/authorization/updateById",
            data: {pIds: fileIds, param: JSON.stringify(jsonData)},
            success: function (data) {
                if (data.code === 0) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/authorization/selectMyPage'//数据接口
                        , where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                } else {
                    layer.msg(data.msg)
                }
            }
        });
    }

    //回显多图片
    $(function () {
        var id = $("#id").val();
        $.ajax({
            type: "POST",
            traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
            url: "${base}/authorization/getImageUrl",
            data: {id: $("#id").val()},
            beforeSend: function () {
                //请求前的处理
            },
            success: function (req) {
                var arr = req.data;//如果前方代码取值不称就用这个：jQuery.parseJSON(data).replies；
                if (arr != null && arr != "") {
                    for (var i = 1; i < req.data.length; i++) {
                        $('#demo2').append('<img src="${base}/team/getPhoto?path=' + arr[i] + '  " class="layui-upload-img" style="width:100px;height:100px">')
                    }
                }
            },
            error: function () {
            }
        });
    })

    //隐藏图片
    function d() {
        $("#demo2 img").remove();
        // var imgs = document.getElementsById("img"); //找出所有的图片
        // for (var i = 0; i < imgs.length; i++) {
        //     imgs[i].style.display = "none"; //将图片隐藏
        // }
    }

</script>
</body>
</html>
